<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <mate name="viewport" content="width=device-width, initial-scale=1.0"></mate>
    <title>消息管理</title>
    <script src="../../static/js/jquery.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.5.0/dist/semantic.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/semantic-ui@2.5.0/dist/semantic.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../static/css/me.css">

</head>
<body>
    <!--导航-->
    <nav th:replace="_fragments :: admin_menu(1)" class="ui inverted attached segment m-padded-tb-tiny">
        <div class="ui container">
            <div class="ui inverted stackable menu secondary ">
                <h2 class="ui teal header  item">广软社区</h2>
                <a href="#" class=" m-item item m-mobile-hide"><i class="small home icon"></i>博客</a>
                <a href="#" class="m-item item m-mobile-hide"><i class="small idea icon"></i>分类</a>
                <a href="#" class="m-item item m-mobile-hide"><i class="small tags icon"></i>标签</a>
                <div class="right menu m-item m-mobile-hide">
                    <div class="ui dropdown item">
                        <div class="text">
                            <img src="https://picsum.photos/seed/picsum/100/100" alt="" class="ui avatar image">
                            陈炯燏
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="ui menu toggle black basic inverted m-top-right button m-mobile-show">
            <i class="sidebar icon" style="width: 0.1em"></i>
        </a>
    </nav>
    <!--二级菜单-->
    <div th:replace="_fragments :: two_menu(2)" class="ui attached pointing menu">
        <div class="ui container">
            <div class="right menu">
                <a href="blogInput.html" class="item">发布</a>
                <a href="#" class="item teal">列表</a>
            </div>
        </div>
    </div>

    <!--中间内容-->
    <div class="m-container m-padded-tb-large m-height">
        <div class="ui container">
            <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p>恭喜，操作成功</p>
            </div>
            <form method="post" class="ui secondary m-padded-tb-mini segment form">
                <input type="hidden" name="page">
                <div class="inline middle aligned stackable fields">
                    <div class="field">
                        <input type="text" name="title" placeholder="标题">
                    </div>
                    <div class="field">
                        <div class="ui labeled action input">
                            <div class="ui type selection dropdown">
                                <input type="hidden" name="checkId">
                                <i class="dropdown icon"></i>
                                <div class="default text">审核状态</div>
                                <div class="menu">
                                    <div th:each="check : ${checkStatus}" class="item" th:data-value="${check.status}" th:text="${check.des}">已通过</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui labeled action input">
                            <div class="ui type selection dropdown">
                                <input type="hidden" name="typeId">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div th:each="type : ${types}" class="item" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
                                </div>
                            </div>
                            <button id="clear" class="ui clear button">clear</button>
                        </div>

                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommend" name="recommend">
                            <label for="recommend">推荐</label>
                        </div>
                    </div>
                    <div class="field m-padded-small">
                        <a type="button" id="search-btn" class="ui teal basic button"><i class="search small icon"></i>搜索</a>
                    </div>
                    <div class="field m-padded-small">
                        <a href="/admin/blogInput" class="ui green basic button"><i class="add small icon"></i>新增</a>
                    </div>
                </div>

            </form>
            <div id="table-container">
                <table th:fragment="blogList" class="ui center aligned compact celled teal table">
                    <thead>
                    <tr>
                        <th></th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>推荐</th>
                        <th th:if="${session.user.roleId==1}">作者</th>
                        <th>发布状态</th>
                        <th>审核状态</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        <tr th:class="${session.user.id == blog.user.id} ? 'positive' : ''"
                            th:each="blog,iterStat : ${page.content}">
                        <td th:text="${iterStat.count}">1</td>
                        <td th:text="${#strings.abbreviate(blog.title,10)}">刻意练习清单</td>
                        <td th:text="${blog.type.name}">认知升级</td>
                        <td th:text="${blog.recommend} ? '是' : '否'">是</td>
                        <td th:if="${session.user.roleId==1}" th:text="${#strings.abbreviate(blog.user.account,8)}">陈炯燏</td>
                        <td th:text="${blog.published} ? '发布' : '草稿'">草稿</td>
                        <td th:if="${blog.status == -1}" class="negative">未通过</td>
                        <td th:if="${blog.status == 0}" class="warning">审核中</td>
                        <td th:if="${blog.status == 1}" class="positive">已通过</td>
                        <td th:text="${blog.updateTime}">2023-10-02</td>
                        <td>
                            <a th:if="${session.user.id==blog.user.id}" href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui mini teal basic button">编辑</a>
                            <a th:if="${session.user.roleId==1}" href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui mini yellow basic button">审核</a>
                            <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" class="ui mini red basic button">删除</a>
                        </td>
                    </tr>
                    </tbody>
                    <tfoot>
                    <tr>
                        <th colspan="7">
                            <div class="ui pagination menu">
                                <a onclick="page(this)" th:attr="data-page=${page.number}-1"  th:unless="${page.first}" class=" item">上一页</a>
                                <a onclick="page(this)" th:attr="data-page=${page.number}+1"  th:unless="${page.last}" class=" item">下一页</a>
                            </div>
                        </th>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>


    <!--底部footer-->
    <footer th:replace="_fragments :: footer" class="ui inverted vertical segment m-padded-tb-max">
        <div class="ui center aligned container">
            <div class="ui inverted divided stackable grid">
                <div class="three wide column">
                    <div class="ui inverted list">
                        <div class="item">
                            <img src="../../static/images/scanner_picture.jpg" class="ui rounded image" alt="站长二维码" style="width: 120px;">
                        </div>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item" > 用户故事（User Story）</a>
                        <a href="#" class="item" > 用户故事（User Story）</a>
                        <a href="#" class="item" > 用户故事（User Story）</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced">联系我</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item" > Email:1718707267@qq.com</a>
                        <a href="#" class="item" > QQ:1718707267</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">ChenJionyu</h4>
                    <p class="m-text-thin m-text-spaced m-text-lined m-opacity-mini">这是我的个人博客，会分享关于编程、写作、思考、相关徳任何内容，希望可以给来到这儿的人有所帮助...</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="m-text-thin m-text-spaced m-opacity-mini">Copyright ©2023 DaiYan Designed by ChenJiongyu </p>
        </div>
    </footer>

    <script>
        const listCheck = ['未通过','审核中','通过']
        $(".menu.toggle").click(function (){
            $(".m-item").toggleClass("m-mobile-hide");
        })
        $(".ui.dropdown").dropdown({
            on:'hover'
        });

        /*点击关闭关闭提示框*/
        $(".message .close").on("click",function () {
            $(this).closest('.message')
                .transition("fade");
        })

        $(".clear.button").on('click',function () {
            $(".ui.type.dropdown").dropdown("clear");
        });

        function page(obj){
            $('[name="page"]').val($(obj).data("page"));
            loaddate();
        }

        $("#search-btn").click(function (){
            $('[name="page"]').val(0);
            loaddate();
        });

        function loaddate(){
            $("#table-container").load(
                "/admin/search",{
                    title:$("[name='title']").val(),
                    typeId:$("[name='typeId']").val(),
                    checkStatusId:$("[name='checkId']").val(),
                    recommend:$("[name='recommend']").prop('checked'),
                    page:$("[name='page']").val()
                }
            );
        }
    </script>
</body>
</html>